﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using aier.dataaccess.model;
using Dapper;


namespace aier.dataaccess.dapper
{
    public class HospitalDal
    {
        public DapperHelper dapperHelper { get; set; }

        public List<HospitalView> GetAllHospital()
        {
            List<HospitalView> hospitalModels = null;

            dapperHelper.ExecueWithoutTransaction(a =>
            {
                string sql = @"select * from AIER_SITE_INFO";

                hospitalModels = a.Query<HospitalView>(sql).ToList();
            });

            return hospitalModels;
        }

        /// <summary>
        /// 根据医院ID查询医院信息
        /// </summary>
        /// <param name="hospitalId">医院ID</param>
        /// <returns></returns>
        public HospitalView GetHospitalById(Guid hospitalId)
        {
            return dapperHelper.ExecueWithoutTransaction(a =>
            {
                string sql = $@"select * from new_hospitalbase where new_hospitalId='{hospitalId}' ";

                SqlBuilder sqlBuilder = new SqlBuilder();
                var sqlTemplate = sqlBuilder.AddTemplate(sql);
                return a.QueryFirstOrDefault<HospitalView>(sqlTemplate.RawSql);
            });

        }
    }
}
